<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="报表月份" prop="bbrq">
        <el-date-picker
          :editable="false"
          clearable
          size="small"
          v-model="queryParams.bbrq"
          type="monthrange"
          range-separator="至"
          start-placeholder="开始月份"
          end-placeholder="结束月份"
          value-format="yyyy-MM"
        >
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="产量合计" prop="sumcl">
        <el-input
          v-model="queryParams.sumcl"
          placeholder="请输入产量合计"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考勤时间合计" prop="sumkq">
        <el-input
          v-model="queryParams.sumkq"
          placeholder="请输入考勤时间合计"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产时间合计" prop="sumsc">
        <el-input
          v-model="queryParams.sumsc"
          placeholder="请输入生产时间合计"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="理论产量合计" prop="sumll">
        <el-input
          v-model="queryParams.sumll"
          placeholder="请输入理论产量合计"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客观扣除合计" prop="sumkg">
        <el-input
          v-model="queryParams.sumkg"
          placeholder="请输入客观扣除合计"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单班产出率合计" prop="sumdb">
        <el-input
          v-model="queryParams.sumdb"
          placeholder="请输入单班产出率合计"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="一类工时合计" prop="sum1">
        <el-input
          v-model="queryParams.sum1"
          placeholder="请输入一类工时合计"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="二类工时合计" prop="sum2">
        <el-input
          v-model="queryParams.sum2"
          placeholder="请输入二类工时合计"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工时总合计" prop="sumall">
        <el-input
          v-model="queryParams.sumall"
          placeholder="请输入工时总合计"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本月全员人间产出" prop="sumperson">
        <el-input
          v-model="queryParams.sumperson"
          placeholder="请输入本月全员人间产出"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属基地" prop="jd">
        <el-input
          v-model="queryParams.jd"
          placeholder="请输入所属基地"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报表编号" prop="bbbh">
        <el-input
          v-model="queryParams.bbbh"
          placeholder="请输入报表编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="[
            'analysis_singelproduction:analysis_singelproduction:add',
          ]"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="[
            'analysis_singelproduction:analysis_singelproduction:edit',
          ]"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="[
            'analysis_singelproduction:analysis_singelproduction:remove',
          ]"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="[
            'analysis_singelproduction:analysis_singelproduction:export',
          ]"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="analysis_singelproductionList"
      @selection-change="handleSelectionChange"
      max-height="550"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" width="100px" />
      <el-table-column label="报表月份" align="center" prop="bbrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bbrq, "{y}-{m}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="产量合计" align="center" prop="sumcl" />
      <!-- <el-table-column label="考勤时间合计" align="center" prop="sumkq" /> -->
      <!-- <el-table-column label="生产时间合计" align="center" prop="sumsc" /> -->
      <!-- <el-table-column label="理论产量合计" align="center" prop="sumll" />
      <el-table-column label="客观扣除合计" align="center" prop="sumkg" />
      <el-table-column label="单班产出率合计" align="center" prop="sumdb" />
      <el-table-column label="一类工时合计" align="center" prop="sum1" />
      <el-table-column label="二类工时合计" align="center" prop="sum2" />
      <el-table-column label="工时总合计" align="center" prop="sumall" />
      <el-table-column label="本月全员人间产出" align="center" prop="sumperson" /> -->
      <el-table-column label="所属基地" align="center" prop="jd" />
      <el-table-column label="报表编号" align="center" prop="bbbh" />
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="250px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="excelhandleView(scope.row)"
            >导出</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="[
              'analysis_singelproduction:analysis_singelproduction:edit',
            ]"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="[
              'analysis_singelproduction:analysis_singelproduction:remove',
            ]"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改仰口生产报对话框 -->
    <!-- <el-dialog fullscreen :title="title" :visible.sync="open" width="900px" append-to-body> -->
    <el-dialog
      fullscreen
      :title="title"
      :visible.sync="open"
      width="900px"
      append-to-body
      custom-class="myDialog"
    >
      <TableHeader
        @nameChange="nameChange"
        @nameChange2="nameChange2"
        :data="{
          mainTitle: '生产部（仰口）基地单班生产产出统计月报表',
          company: form.jd,
          code: form.bbbh,
        }"
      />
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="报表月份" prop="bbrq">
              <el-date-picker
                :editable="false"
                clearable
                size="small"
                v-model="form.bbrq"
                type="month"
                value-format="yyyy-MM"
                placeholder="选择报表月份"
                :disabled="openDisabled"
                @change="selectOption2"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <!-- <el-col :span="12">
                <el-form-item label="所属基地" prop="jd">
                  <el-input v-model="form.jd" placeholder="请输入所属基地" :disabled="openDisabled" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="报表编号" prop="bbbh">
                  <el-input v-model="form.bbbh" placeholder="请输入报表编号" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
        </el-row>
        <br />
        <el-divider content-position="center"
          >仰口生产产出月报表子信息</el-divider
        >
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddRptAnalysisSingelproductionSub"
              :disabled="openDisabled"
              >添加</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDeleteRptAnalysisSingelproductionSub"
              :disabled="openDisabled"
              >删除</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="summation()"
              :disabled="openDisabled"
              >统计</el-button
            >
          </el-col>
        </el-row>
        <el-table
          :data="rptAnalysisSingelproductionSubList"
          :row-class-name="rowRptAnalysisSingelproductionSubIndex"
          @selection-change="
            handleRptAnalysisSingelproductionSubSelectionChange
          "
          ref="rptAnalysisSingelproductionSub"
          max-height="550"
        >
          <el-table-column type="selection" width="50" align="center" />
          <!-- <el-table-column
            label="序号"
            align="center"
            prop="index"
            width="50"
          /> -->
          <el-table-column label="报表日期" prop="bbyf" minWidth="110">
            <!-- <template slot-scope="scope"> -->
            <!-- <el-input v-model="scope.row.bbyf" placeholder="请输入报表月份" :disabled="openDisabled"/> -->
            <!-- <el-select v-model="scope.row.bbyf" @change="selectOption(scope)" :disabled="openDisabled">
                <el-option value="1">1</el-option>
                <el-option value="2">2</el-option>
                <el-option value="3">3</el-option>
                <el-option value="4">4</el-option>
                <el-option value="5">5</el-option>
                <el-option value="6">6</el-option>
                <el-option value="7">7</el-option>
                <el-option value="8">8</el-option>
                <el-option value="9">9</el-option>
                <el-option value="10">10</el-option>
                <el-option value="11">11</el-option>
                <el-option value="12">12</el-option>
                <el-option value="13">13</el-option>
                <el-option value="14">14</el-option>
                <el-option value="15">15</el-option>
                <el-option value="16">16</el-option>
                <el-option value="17">17</el-option>
                <el-option value="18">18</el-option>
                <el-option value="19">19</el-option>
                <el-option value="20">20</el-option>
                <el-option value="21">21</el-option>
                <el-option value="22">22</el-option>
                <el-option value="23">23</el-option>
                <el-option value="24">24</el-option>
                <el-option value="25">25</el-option>
                <el-option value="26">26</el-option>
                <el-option value="27">27</el-option>
                <el-option value="28">28</el-option>
                <el-option value="29">29</el-option>
                <el-option value="30">30</el-option>
                <el-option value="31">31</el-option>
              </el-select>
            </template> -->

            <template slot-scope="scope">
              <el-input
                v-model="scope.row.bbyf"
                placeholder="日期"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <el-table-column label="产量" prop="cl" minWidth="140">
            <template slot-scope="scope">
              <el-input
                type="number"
                v-model="scope.row.cl"
                placeholder="请输入产量"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <el-table-column label="考勤时间" prop="kqsj" minWidth="140">
            <template slot-scope="scope">
              <el-input
                type="number"
                v-model="scope.row.kqsj"
                @change="subtraction(scope)"
                placeholder="请输入考勤时间"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <el-table-column label="生产时间" prop="scsj" minWidth="140">
            <template slot-scope="scope">
              <el-input
                type="number"
                v-model="scope.row.scsj"
                placeholder="请输入生产时间"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <el-table-column label="理论产量" prop="llcl" minWidth="140">
            <template slot-scope="scope">
              <el-input
                type="number"
                v-model="scope.row.llcl"
                placeholder="请输入理论产量"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <el-table-column label="客观扣除时间" prop="kgkcsj" minWidth="170">
            <template slot-scope="scope">
              <el-input
                type="number"
                v-model="scope.row.kgkcsj"
                @change="subtraction2(scope)"
                placeholder="请输入客观扣除时间"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="remark" minWidth="250">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.remark"
                placeholder="请输入备注信息"
                :disabled="openDisabled"
                type="textarea"
              />
            </template>
          </el-table-column>

          <el-table-column label="单班产出率" prop="dbccl" minWidth="160">
            <template slot-scope="scope">
              <el-input
                type="number"
                v-model="scope.row.dbccl"
                placeholder="请输入单班产出率"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <el-table-column label="一类工时" prop="gs1" minWidth="140">
            <template slot-scope="scope">
              <el-input
                type="number"
                v-model="scope.row.gs1"
                placeholder="请输入一类工时"
                :disabled="openDisabled"
                @change="automatic1(scope)"
              />
            </template>
          </el-table-column>
          <el-table-column label="二类工时" prop="gs2" minWidth="140">
            <template slot-scope="scope">
              <el-input
                type="number"
                v-model="scope.row.gs2"
                placeholder="请输入二类工时"
                :disabled="openDisabled"
                @change="automatic2(scope)"
              />
            </template>
          </el-table-column>
          <el-table-column label="工时汇总" prop="gsall" minWidth="140">
            <template slot-scope="scope">
              <el-input
                type="number"
                v-model="scope.row.gsall"
                placeholder="请输入工时汇总"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <!-- <el-table-column label="备注" prop="remark">
            <template slot-scope="scope">
              <el-input
               type="number"
                v-model="scope.row.remark"
                placeholder="请输入内容"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column> -->
        </el-table>

        <el-col :span="8">
          <el-form-item label="产量合计" prop="sumcl">
            <el-input
              type="number"
              v-model="form.sumcl"
              placeholder="产量合计"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="考勤时间合计" prop="sumkq">
            <el-input
              type="number"
              v-model="form.sumkq"
              placeholder="考勤时间合计"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="生产时间合计" prop="sumsc">
            <el-input
              type="number"
              v-model="form.sumsc"
              placeholder="生产时间合计"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="理论产量合计" prop="sumll">
            <el-input
              type="number"
              v-model="form.sumll"
              placeholder="理论产量合计"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="客观扣除合计" prop="sumkg">
            <el-input
              type="number"
              v-model="form.sumkg"
              placeholder="客观扣除合计"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="单班产出率" prop="sumdb">
            <el-input
              type="number"
              v-model="form.sumdb"
              placeholder="单班产出率"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="一类工时合计" prop="sum1">
            <el-input
              type="number"
              v-model="form.sum1"
              placeholder="一类工时合计"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="二类工时合计" prop="sum2">
            <el-input
              type="number"
              v-model="form.sum2"
              placeholder="二类工时合计"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="工时总合计" prop="sumall">
            <el-input
              type="number"
              v-model="form.sumall"
              placeholder="工时总合计"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="本月全员人均产出" prop="sumperson">
            <el-input
              type="number"
              v-model="form.sumperson"
              placeholder="本月全员人均产出"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="协助工时" prop="assistwork">
            <el-input
              type="number"
              v-model="form.assistwork"
              placeholder="协助工时"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="协助说明" prop="assistremark">
            <el-input v-model="form.assistremark" placeholder="协助说明" />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listAnalysis_singelproduction,
  getAnalysis_singelproduction,
  delAnalysis_singelproduction,
  addAnalysis_singelproduction,
  updateAnalysis_singelproduction,
  queryCount,
  querysum,
} from "@/api/report/analysis/analysis_singelproduction";

export default {
  name: "Analysis_singelproduction",
  data() {
    return {
      //弹窗是否禁止编辑
      openDisabled: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedRptAnalysisSingelproductionSub: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 仰口生产报表格数据
      analysis_singelproductionList: [],
      // 仰口生产报子表格数据
      rptAnalysisSingelproductionSubList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        bbrq: null,
        bbrq1: null,
        sumcl: null,
        sumkq: null,
        sumsc: null,
        sumll: null,
        sumkg: null,
        sumdb: null,
        sum1: null,
        sum2: null,
        sumall: null,
        sumperson: null,
        jd: null,
        bbbh: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      querysum: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    createValue() {
      // console.log(this.rptAnalysisSingelproductionSubList);
    },
    //选择月份触发事件
    selectOption2(event) {
      let sp = event.split("-");
      queryCount({ rptYear: sp[0], rptMonth: sp[1] }).then((response) => {
        this.querysum = response.data;
        this.rptAnalysisSingelproductionSubList = [];
        this.form.rptAnalysisSingelproductionSubList = [];

        this.querysum.forEach((item) => {
          let obj = {};
          obj.bbyf = item.scrq;
          obj.cl = item.monthBoxCount;
          obj.kqsj =item.kqsj;
          obj.scsj =item.scsj;
          obj.llcl = "";
          obj.kgkcsj = "";
          obj.dbccl = "";
          obj.gs1 = item.type1;
          obj.gs2 = item.type2;
          obj.gsall = parseFloat(item.type1) + parseFloat(item.type2);
          obj.remark = "";
          this.rptAnalysisSingelproductionSubList.push(obj);
        });

        this.form.rptAnalysisSingelproductionSubList =
          this.rptAnalysisSingelproductionSubList;
      });
      // }
    },
    automatic1(scope) {
      // console.log(333, scope);
      this.rptAnalysisSingelproductionSubList[scope.$index].gs1 = scope.row.gs1;
      this.rptAnalysisSingelproductionSubList[scope.$index].gsall =
        Number(this.rptAnalysisSingelproductionSubList[scope.$index].gs1) +
        Number(this.rptAnalysisSingelproductionSubList[scope.$index].gs2);
    },
    automatic2(scope) {
      // console.log(333, scope);
      this.rptAnalysisSingelproductionSubList[scope.$index].gs2 = scope.row.gs2;
      this.rptAnalysisSingelproductionSubList[scope.$index].gsall =
        Number(this.rptAnalysisSingelproductionSubList[scope.$index].gs1) +
        Number(this.rptAnalysisSingelproductionSubList[scope.$index].gs2);
    },
    //选择日期获取产量
    // selectOption(scope) {
    //   if (this.form.bbrq != null && this.form.bbrq != "") {
    //     queryCount({ rptDate: this.form.bbrq+'-'+scope.row.bbyf }).then((response) => {
    //       // this.querysum = response;
    //       // console.log(response.data.monthBoxCount);
    //       this.rptAnalysisSingelproductionSubList[scope.$index].cl = response.data.monthBoxCount;
    //     });

    //     querysum({ rptDate: this.form.bbrq }).then((response) => {
    //       // console.log(response.rows);
    //       this.querysum = response;
    //       console.log(this.querysum);
    //     });

    //   }
    // },
    //考勤时间
    subtraction(scope) {
      scope.row.scsj = scope.row.kqsj - 1;
    },
    //客观扣除时间
    subtraction2(scope) {
      scope.row.llcl = 750 * (scope.row.scsj - scope.row.kgkcsj);
      //单班产率
      if(!scope.row.cl||scope.row.cl==0||!scope.row.llcl||scope.row.llcl==0)
      {
        return;
      }
      scope.row.dbccl = ((scope.row.cl / scope.row.llcl) * 100).toFixed(2);
      //scope.row.dbccl += "%";
    },
    /** 查询仰口生产报列表 */
    getList() {
      this.loading = true;
      listAnalysis_singelproduction(this.queryParams).then((response) => {
        this.analysis_singelproductionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        bbrq: null,
        sumcl: null,
        sumkq: null,
        sumsc: null,
        sumll: null,
        sumkg: null,
        sumdb: null,
        sum1: null,
        sum2: null,
        sumall: null,
        sumperson: null,
        jd: "仰口生产基地",
        bbbh: "LK-QF-LS1-10-007-11-01",
        delFlag: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.rptAnalysisSingelproductionSubList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.bbrq != null) {
        let arr = this.queryParams.bbrq;
        this.queryParams.bbrq = arr[0];
        this.queryParams.bbrq1 = arr[1];
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openDisabled = false;
      this.open = true;
      this.title = "添加单班生产产出统计月报表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.openDisabled = false;
      const id = row.id || this.ids;
      getAnalysis_singelproduction(id).then((response) => {
        this.form = response.data;
        this.rptAnalysisSingelproductionSubList =
          response.data.rptAnalysisSingelproductionSubList;
        this.open = true;
        this.title = "修改单班生产产出统计月报表";
      });
    },
    /** 查看按钮 */
    handleView(row) {
      this.reset();
      this.openDisabled = true;
      const id = row.id || this.ids;
      getAnalysis_singelproduction(id).then((response) => {
        this.form = response.data;
        this.rptAnalysisSingelproductionSubList =
          response.data.rptAnalysisSingelproductionSubList;
        this.open = true;
        this.title = "查看单班生产产出统计月报表";
      });
    },
    /** 计算合计 */
    summation() {
      this.form.sumcl = 0;
      this.form.sumkq = 0;
      this.form.sumsc = 0;
      this.form.sumll = 0;
      this.form.sumkg = 0;
      this.form.sumdb = 0;
      this.form.sum1 = 0;
      this.form.sum2 = 0;
      this.form.sumall = 0;
      this.form.rptAnalysisSingelproductionSubList.forEach((item) => {
        // console.log(item);
        this.form.sumcl += Number(item.cl);
        this.form.sumkq += Number(item.kqsj);
        this.form.sumsc += Number(item.scsj);
        this.form.sumll += Number(item.llcl);
        this.form.sumkg += Number(item.kgkcsj);
        this.form.sum1 += Number(item.gs1);
        this.form.sum2 += Number(item.gs2);
        this.form.sumall += Number(item.gsall);
      });
      //0值判断 单班产出率 =  产量合计/理论产量
      if (this.form.sumll == 0 || this.form.sumll == null) {
        this.form.sumdb = 0;
      } else {
        this.form.sumdb += (
          Number(this.form.sumcl) / Number(this.form.sumll)
        ).toFixed(2);
      }

      // 工时总合计=一类工时+二类工时+协助工时
      if (this.form.assistwork == null) {
      } else {
        this.form.sumall = this.form.sumall + Number(this.form.assistwork);
      }

      //0值判断 本月全员人均产出=产量合计 / 工时总合计
      if (
        this.form.sumcl == null ||
        this.form.sumcl == 0 ||
        this.form.sumall == null ||
        this.form.sumall == 0
      ) {
        this.form.sumperson = 0;
      } else {
        // this.form.sumperson = Number(this.form.sumcl / this.form.sumall).toFixed(2);
        this.form.sumperson = Number(
          this.form.sumcl / this.form.sumall
        ).toFixed(2);
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.rptAnalysisSingelproductionSubList =
            this.rptAnalysisSingelproductionSubList;
          this.summation();
          if (this.form.id != null) {
            updateAnalysis_singelproduction(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAnalysis_singelproduction(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除仰口生产产出月报表编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delAnalysis_singelproduction(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 仰口生产报子序号 */
    rowRptAnalysisSingelproductionSubIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 仰口生产报子添加按钮操作 */
    handleAddRptAnalysisSingelproductionSub() {
      if (this.form.bbrq == "" || this.form.bbrq == null) {
        this.msgError("请选择报表月份");
      } else {
        let obj = {};
        obj.bbyf = "";
        obj.cl = "";
        obj.remark = "";
        obj.kqsj = "";
        obj.scsj = "";
        obj.llcl = "";
        obj.kgkcsj = "";
        obj.dbccl = "";
        obj.gs1 = "";
        obj.gs2 = "";
        obj.gsall = "";
        obj.remark = "";
        this.rptAnalysisSingelproductionSubList.push(obj);
      }
    },
    /** 仰口生产报子删除按钮操作 */
    handleDeleteRptAnalysisSingelproductionSub() {
      if (this.checkedRptAnalysisSingelproductionSub.length == 0) {
        this.$alert("请先选择要删除的仰口生产产出月报表子数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.rptAnalysisSingelproductionSubList.splice(
          this.checkedRptAnalysisSingelproductionSub[0].index - 1,
          1
        );
      }
    },
    /** 单选框选中数据 */
    handleRptAnalysisSingelproductionSubSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.rptAnalysisSingelproductionSub.clearSelection();
        this.$refs.rptAnalysisSingelproductionSub.toggleRowSelection(
          selection.pop()
        );
      } else {
        this.checkedRptAnalysisSingelproductionSub = selection;
      }
    },
    excelhandleView(row) {
      this.download(
        "productionProcess/analysis_singelproduction/exportexcel?id=" + row.id,
        {
          ...this.queryParams,
        },
        "仰口单班产出率" + row.bbrq + ".xlsx"
      );
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "productionProcess/analysis_singelproduction/export",
        {
          ...this.queryParams,
        },
        "仰口生产产出月报表" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    //接收编号
    nameChange(e) {
      this.form.bbbh = e;
    },
    //接收编号
    nameChange2(e) {
      this.form.jd = e;
    },
  },
};
</script>
